class Solution:
    def myAtoi(self, str_t: str) -> int:
        k = 0
        if len(str_t) == 1 and (str_t == '+' or str_t == '-'):
            return 0

        if str_t.isspace() == True:
            return 0
        if str_t == "":
            return 0
        if len(str_t) == 1 and int(str_t) in range(0, 10):
            return int(str_t)
        result = {}  # 用于存放结果的数组
        str_t = list(str_t)

        def test_zf(str_t):  # 如果两个符号连在一起呢？

            for i in range(len(str_t)):
                if str_t[i] != " ":
                    if str_t[i] == "-":
                        if str_t[i + 1] != "0" and str_t[i + 1] != "1" and str_t[i + 1] != "2" and str_t[
                            i + 1] != "3" and str_t[i + 1] != "4" and str_t[i + 1] != "5" and str_t[i + 1] != "6" and \
                                str_t[i + 1] != "7" and str_t[i + 1] != "8" and str_t[i + 1] != "9":
                            return 0
                        return -1
                    elif str_t[i] == '0' or str_t[i] == '1' or str_t[i] == '2' or str_t[i] == '3' or str_t[i] == '4' or \
                            str_t[i] == '5' or str_t[i] == '6' or str_t[i] == '7' or str_t[i] == '8' or str_t[
                        i] == '9' or str_t[i] == '+':
                        if str_t[i + 1] == '-' or str_t[i + 1] == '+' or str_t[i + 1] == " ":
                            return 0
                        if str_t[i + 1] != "0" and str_t[i + 1] != "1" and str_t[i + 1] != "2" and str_t[
                            i + 1] != "3" and str_t[i + 1] != "4" and str_t[i + 1] != "5" and str_t[i + 1] != "6" and \
                                str_t[i + 1] != "7" and str_t[i + 1] != "8" and str_t[i + 1] != "9":
                            k = i
                            return 4
                        return 1
                    else:
                        print("不能转换")
                        return 0

        if test_zf(str_t) == 4:
            if str_t[k] == '0' or str_t[k] == '1' or str_t[k] == '2' or str_t[k] == '3' or str_t[k] == '4' or str_t[
                k] == '5' or str_t[k] == '6' or str_t[k] == '7' or str_t[k] == '8' or str_t[k] == '9':

                return int(str_t[k])
            else:
                return 0
        # 提取数字
        j = 0
        for i in range(len(str_t)):
            if str_t[i] == "0" or str_t[i] == "1" or str_t[i] == "2" or str_t[i] == "3" or str_t[i] == "4" or str_t[
                i] == "5" or str_t[i] == "6" or str_t[i] == "7" or str_t[i] == "8" or str_t[i] == "9":
                if i - 1 < 0 or j == 0:
                    result[j] = str_t[i]
                    j = j + 1
                    continue
                if str_t[i - 1] != "0" and str_t[i - 1] != "1" and str_t[i - 1] != "2" and str_t[i - 1] != "3" and \
                        str_t[i - 1] != "4" and str_t[i - 1] != "5" and str_t[i - 1] != "6" and str_t[i - 1] != "7" and \
                        str_t[i - 1] != "8" and str_t[i - 1] != "9":
                    print("cuo")
                    break
                result[j] = str_t[i]
                j = j + 1

        # 将元素全部转换为整数
        for i in range(len(result)):
            result[i] = int(result[i])

        # 将整数拼装起来
        the_sum = 0  # 最终结果
        j = len(result)
        for i in range(len(result)):
            the_sum = the_sum + result[i] * pow(10, j - 1)
            j = j - 1

        if test_zf(str_t) == 0:
            return 0
        the_sum = the_sum * test_zf(str_t)

        if the_sum > 2147483647:
            return 2147483647
        if the_sum < -2147483648:
            return -2147483648
        return the_sum


s = "     1l1361065549"
print(Solution.myAtoi(str_t=s))
